package com.example.demo_videos.controller;

import com.example.demo_videos.service.VideoInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/video/aliyunVod")
@CrossOrigin
public class VodController {

    @Resource
    private VideoInfoService videoInfoService;

    @PostMapping("/uploadVideo")
    @ResponseBody
    public String  uploadVideo(MultipartFile file){
       int uploadResult =  videoInfoService.uploadVideoAliyun(file);
       if(uploadResult==0)
           return "上传失败";

           return "上传成功";
    }

    @RequestMapping("/videoPlay")
    public String videoPlay(String vid,Model model){
       String playAuth = videoInfoService.getPlayAuth(vid);
       model.addAttribute("vid",vid);
       model.addAttribute("playAuth",playAuth);
       return "playVideo";
    }

    @RequestMapping("/videoList")
    @ResponseBody
    public List videoList(){
        return videoInfoService.getVideoList();
    }
}
